<#setting number_format="#">
String.prototype.startsWith = function(str){
	return (this.match("^"+str)==str)
}
$(function(){
	var totalPage=${totalPage}
	$('#bockerName').html('<a href="http://t.sohu.com/n/${bockerName}" target="_blak">${bockerName}</a>')
	var nav='<div class="nav top">';
	if(currentIndex>1){
		nav+='<a href="javascript:page(1)">首页</a>&nbsp;<a href="javascript:page('+(currentIndex-1)+')">上页'+'</a>'
	}
	nav+='&nbsp;&nbsp;'+currentIndex+'&nbsp;/&nbsp;'+totalPage+'&nbsp;&nbsp;'
	if(currentIndex<totalPage){
		nav+='<a href="javascript:page('+(currentIndex+1)+')">下页'+'</a>&nbsp<a href="javascript:page('+totalPage+')">末页</a>'
	}
	nav+='&nbsp; 总微博数：${totalComment}'
	<#if searchKey?exists>
	nav+='&nbsp;&nbsp;搜索关键字:&nbsp;<span>${searchKey}</span>'
	</#if>
	nav+='</div>'
	$('#bockerName').after(nav)
	$('body').append(nav.replace(' top',''))
	addDivs();
	$('a').each(function(){
		var title=$(this).attr('title');
		var href=$(this).attr('href');
		if(href.charAt(0)=='/'){
			$(this).attr('href','http://t.sohu.com'+href);
		}
		if(title==undefined){
			return;
		}
		title=title.toLowerCase()
		if(title.startsWith('http://')||title.startsWith("https://")){
			$(this).attr('href',title);
		}
	})
	
	$('div.img img').click(function(){
		var curTime=new Date().getTime();
		if(curTime>oldTime+100){
			oldTime=curTime;
			var div=$(this).parent('div');
			div.attr('class',div.attr('class')=='img'?'actualImg':'img');
		}
	})
})
function page(index){
	window.open((10000+index+'.html').substring(1),'_self')
}
var oldTime=0;
function addDiv(id,time,rid,author){
	var cm=eval('c'+id);
	var html='<li id="t'+id+'">';
	if(rid&&cm['pics'].length>0){
		html+=toImgHtml(cm['pics']);
	}
	html+='<div><span class="time">'+time+':&nbsp;</span>'+cm['content']['data']+'<br/>';
	if(!rid&&cm['pics'].length>0){
		html+=toImgHtml(cm['pics']);
	}
	html+='</div>'
	if(rid){
		if(author==undefined){
			author='${bockerName}';
		}
		var rt=eval('c'+rid);
		html+='<div class="root"><a href="http://t.sohu.com/n/'+author+'" target="_blank">@'+author+':</a>'+rt['content']['data']+'<br/>';
		if(rt['pics'].length>0){
			html+=toImgHtml(rt['pics']);
		}
		html+='</div>';
	}
	html+='</li>';
	$('ul.content').append(html);
	//TODO
}
function toImgHtml(pics){
	var html='<div class="img">';
	for(var i=0;i<pics.length;i++){
		html+='<img src="<#if searchKey?exists>../</#if>'+pics[i]+'" />&nbsp;'
	}
	html+='</div>';
	return html;
}
